﻿using Runtime.Models;
using Runtime.Services.BattleSkill;

namespace Runtime.Services.Battle.Behaviour {

    /// <summary>
    /// 效果触发行为
    /// </summary>
    public interface IDFR_BattleBehaviour_Trigger : IDFR_BattleBehaviour {

        public static readonly DFR_BattleBehaviourType TYPE = new() { Value = int.MaxValue - 1 };

        /// <summary>
        /// 实体
        /// </summary>
        new public interface IEntity : IDFR_BattleBehaviour.IEntity {

            /// <summary>
            /// CD总时间
            /// </summary>
            IDFR_BattleData CoolDownBase { get; }

            /// <summary>
            /// CD经过时间
            /// </summary>
            IDFR_BattleData CoolDownDuration { get; }

            /// <summary>
            /// 技能数据
            /// </summary>
            IDFR_BattleSkillModelTD SkillModel { get; }

            /// <summary>
            /// 效果数据
            /// </summary>
            IDFR_BattleEffectModelTD EffectModel { get; }

            /// <summary>
            /// 索敌
            /// </summary>
            IDFR_BattleEffectLookout Lookout { get; }
        }
    }

    [Implement(typeof(IDFR_BattleBehaviour_Trigger))]
    internal sealed class DFR_BattleBehaviour_Trigger : DFR_BattleBehaviour, IDFR_BattleBehaviour_Trigger {

        new private IDFR_BattleBehaviour_Trigger.IEntity Entity => (IDFR_BattleBehaviour_Trigger.IEntity)base.Entity;

        protected override void Initialize() {
        }

        protected override IDFR_BattleBehaviourInfo LogicFrame() {
            Entity.CoolDownDuration.Value -= Entity.CoolDownBase.Value;
            if (BattleSkillServiceTD.Instance.TriggerEffect(Entity.EffectModel, Entity.SkillModel, Entity.Lookout)) {
                return new DFR_BattleBehaviourInfo {
                    Type = IDFR_BattleBehaviour_Trigger.TYPE,
                };
            }
            return null;
        }

        protected override void Execute(IDFR_BattleBehaviourInfo info) {
        }

        protected override void Update(IDFR_BattleBehaviourInfo info, float interpolation) {
            if (StateMachine != null) {
                StateMachine.State = DFR_BattleEntityState.Attack;
            }
        }
    }
}
